<?php
session_start();
include_once "../qc_base.php";
include_once "../qc_utils.php";
include_once "../bootstrap.php";
include_once "../lib/phpctls/PhpCtls.php";
//include_once "../qc_base.php";
//include_once "../qc_utils.php";
//require_once('../bootstrap.php');
//require_once('../lib/spyc/spyc.php');

include_once "../lib/createfastlib/CF_Functions/CF_support.php";

// each variable in this array may have it's own sub menu when it is set (by request)
$arGroupTypes = array('project_id','crudset_id','crudcol_id','filter_id');
$arMenuGroups = array();

$arParameters = array();

//$project_id = $_REQUEST['project_id'];
//$arParameters['project_id'] = $_REQUEST['project_id'];

$project_id = GetPersistent('project_id');
$arParameters['project_id'] = $project_id;

$crudset_id = GetPersistent('crudset_id');
$arParameters['crudset_id'] = $crudset_id;





if (!isset($_REQUEST['crudset_id'])  ){
	//print '<br>NO CRUDSET SELECTED</br>';

}else{
	//print '<br>Crudset = ' . $crudset_id . '</br>';
	$arParameters['crudset_id'] = $_REQUEST['crudset_id'];
}




if ($handle = opendir("../actions")) {
	$i = 0;
 while (($file = readdir($handle)) !== false) {
 	//print "Checking $file <br />";
	if(!is_dir($file)){ // This function dosent' work right it seems to 
	//only return true for . and .. so I negated it for now since there should be only directories in here
		
		//$arr_template_dirs [$i] ['keyvalue'] = 'templates/' . $file . '/';
		//$arr_template_dirs [$i] ['showvalue'] = 'templates/' .$file . '/';
		
		if(file_exists("../actions/" . $file . '/menu.php')){
			include "../actions/" . $file . '/menu.php';
			foreach($arGroupTypes as $type){
				if(is_array($menu[$type])){
					//$newlink = '<li><a href="../actions/' . $file . '/' . $menu[$type]['link'] . '?project_id=' . $project_id . '&crudset_id=' . $crudset_id . ' ">' . $menu[$type]['text'] . '</a></li>' . "\n";
					$newlink = '<li><a href="javascript:RunActionRemote(\'../actions/' . $file . '/' . $menu[$type]['link'] . '?project_id=' . $project_id . '&crudset_id=' . $crudset_id . ' \')" >' . $menu[$type]['text'] . '</a></li>' . "\n";

					$arMenuGroups[$type][] = $newlink;
					//$menutext .= $newlink;
				}
			
			}
			
		}else{
		//$menutext .= '<li><a href="../actions/' . $file . '/run-web.php?project_id=' . $project_id . '&crudset_id=' . $crudset_id . ' ">NOMENU' . $file . '</a></li>' . "\n";
		}
		unset($menu);
		
		$i ++;
	}

 }

}

?>



<?php

/*
	foreach($arMenuGroups as $param=>$linkset){
		print $param . 'IS' . $arParameters[$param]. "<br>\n";

		if(isset($arParameters[$param])){
			foreach($arMenuGroups[$param] as $link){
				print $link;
			}
		}
	}
*/
	
	
//print_r($arMenuGroups);
?>
<html>
<head>
<script language="JavaScript" src="jquery-1.4.2.min.js"></script>
<script language="JavaScript">
function RunActionRemote(url){
	var currentlog;
	
	currentlog = $('#actions_log').html();
	$.get(url, function(data) {
	
  $('#actions_log').html(currentlog + '<pre>' + data + '</pre><br/>');
  alert('Load was performed.');
});

}
</script>
		<style type="text/css">
		
		</style>
<link rel="stylesheet" href="gui.css" type="text/css">

<title>FrontPage</title>
</head>
<body>
<div id='Header'>

</div>  <!-- End Header -->

<div id='Menu'>
<form name='actmenu' id='act_menu' action=<?php print $_SERVER['PHP_SELF'] ?> method='get' ?>
<?php include "menu_projects.php"; ?>
<?php if(!empty($project_id)){ include "menu_crudsets.php"; } ?>
<?php if(!empty($crudset_id)){ include "menu_crudcols.php"; }?>
</form>
</div> <!-- end Menu -->

<div id='Content'>
<iframe id='mainframe' name='mainframe' width='700' height='450'>Get a new browser</iframe>
<div name='actions_log' id='actions_log'></div>

</div> <!-- end Content -->

</body>
</html>